#include "include/global.h"
#include "include/type.h"
#include "include/proc.h"
#include "include/kconst.h"
void schedule();

void clock_handler(int req) 
{
    if (k_reenter != 0)
        return;
    ticks++;
    
    schedule();
}

void init_clock()
{
    //初始化 8253 计时器
    out_byte(TIMER_MODE, RATE_GENERATE);
	out_byte(TIMER0, 0x9c);
	out_byte(TIMER0, 0x2e);
    put_irq_handler(0,clock_handler);	//设置handler
	enable_irq(0);						//启用时钟中断
}

int get_ticks()
{
    MESSAGE msg;
    reset_msg(&msg);
    msg.type = GET_TICKS;
    send_recv(BOTH, TASK_SYS, &msg);
    return msg.RETVAL;
}

void milli_delay(int milli_second)
{
	u32 i = get_ticks();
    while ((get_ticks() - i) * 10 < milli_second);
}
